package de.unifa.elostplugin.gui.wizards;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;

import de.unifa.elostplugin.gui.wizards.beans.BuildBeanData;
import de.unifa.elostplugin.gui.wizards.beans.BuildBeanDecision;
import de.unifa.elostplugin.gui.wizards.pages.BuildPageBranchRelease;
import de.unifa.elostplugin.gui.wizards.pages.BuildPageDecision;
import de.unifa.elostplugin.gui.wizards.pages.BuildPageLocalNoRelease;
import de.unifa.elostplugin.gui.wizards.pages.BuildPageTrunkMainRelease;
import de.unifa.elostplugin.gui.wizards.pages.BuildPageTrunkRelease;
import de.unifa.elostplugin.gui.wizards.pages.BuildPageTrunktag2Branch;

public class BuildWizard extends Wizard {

	private BuildBeanData data = new BuildBeanData();
	private BuildBeanDecision decision = new BuildBeanDecision();
	private BuildPageDecision pageChoose = new BuildPageDecision();
	private BuildPageLocalNoRelease pageLocalNoRelease = new BuildPageLocalNoRelease();
	private BuildPageBranchRelease pageBranchRelease = new BuildPageBranchRelease();
	private BuildPageTrunkRelease pageTrunkRelease = new BuildPageTrunkRelease();
	private BuildPageTrunkMainRelease pageTrunkMainRelease = new BuildPageTrunkMainRelease();
	private BuildPageTrunktag2Branch pageTrunktag2Branch = new BuildPageTrunktag2Branch();
	
	public BuildWizard() {
		setWindowTitle("Bauassistent");

	}

	/**
	 * @return the data
	 */
	public BuildBeanData getData() {
		return data;
	}

	/**
	 * @return the decision
	 */
	public BuildBeanDecision getDecision() {
		return decision;
	}

	@Override
	public void addPages() {
		addPage(pageChoose);
		addPage(pageLocalNoRelease);
		addPage(pageBranchRelease);
		addPage(pageTrunkRelease);
		addPage(pageTrunkMainRelease);
		addPage(pageTrunktag2Branch);
	}

	@Override
	public IWizardPage getNextPage(IWizardPage page) {
		IWizardPage nextPage = null;
		if (page instanceof BuildPageDecision) {
			
			BuildBeanDecision decision = ((BuildPageDecision) page).getDecision();
			System.out.println(decision);
			if (decision.getLocalNoRelease()) {
				nextPage = pageLocalNoRelease;
			} else if (decision.getBranchRelease()) {
				nextPage = pageBranchRelease;
			} else if (decision.getTrunkRelease()) {
				nextPage = pageTrunkRelease;
			} else if (decision.getTrunkMainRelease()) {
				nextPage = pageTrunkMainRelease;
			} else if (decision.getTrunktag2Branch()) {
				nextPage = pageTrunktag2Branch;
			}

		}
		
		return nextPage;
	}

	@Override
	public boolean canFinish() {
		boolean canFinish= false;
		IWizardPage currentPage = this.getContainer().getCurrentPage();
		if(currentPage.isPageComplete() && !currentPage.equals(pageChoose)){
			canFinish=true;
		}		
		return canFinish;
	}

	@Override
	public boolean performFinish() {
		
		return true;
	}

}
